home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / bildschirmschoner / bserver_v1.5 / sources.lha / Sources / server / modeid.c < prev    next >
C/C++ Source or Header  |  1995-11-08  |  4KB  |  142 lines

  1. #include <exec/memory.h>
  2. #include <graphics/displayinfo.h>
  3. #include <graphics/modeid.h>
  4. #include <string.h>
  5.  
  6. #include <proto/exec.h>
  7. #include <proto/graphics.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "/include/server.h"
  11.  
  12. extern UBYTE briLevel, sndLevel;
  13. extern WORD ActiveClient;
  14. extern struct ClientNode *FindClientNode( WORD );
  15.  
  16. struct List *ModeList;
  17. struct ModeNode *DisplayNode;
  18. ULONG DisplayID = PAL_MONITOR_ID;
  19.  
  20. char DefaultModeName[DISPLAYNAMELEN];
  21.  
  22.  
  23. void DeleteModeList( void )
  24. {
  25. struct ModeNode *ModeNode;
  26.  
  27. while (ModeList->lh_Head->ln_Succ)
  28.     {
  29.     ModeNode=(struct ModeNode *)ModeList->lh_Head;
  30.     RemHead (ModeList);
  31.     FreeVec( ModeNode );
  32.     }
  33. FreeVec( ModeList );
  34. }
  35.  
  36.  
  37. struct List *CreateModeList(void)
  38. {
  39. UWORD Index = 0;
  40. ULONG NewDisplID;
  41. struct DimensionInfo DimInfo;
  42. struct NameInfo NameInfo;
  43. struct ModeNode *NewNode;
  44.  
  45. if ( ModeList = AllocVec( sizeof(struct List), MEMF_PUBLIC ) )
  46.     NewList( ModeList );
  47. else
  48.     return( NULL );
  49.  
  50. NewDisplID=INVALID_ID;
  51.  
  52. while ( ( NewDisplID = NextDisplayInfo( NewDisplID ) ) != INVALID_ID )
  53.     if ( ( NewDisplID & MONITOR_ID_MASK ) && ( !ModeNotAvailable( NewDisplID ) ) )
  54.         if ( GetDisplayInfoData( NULL, (UBYTE *)&DimInfo, sizeof(struct DimensionInfo), DTAG_DIMS, NewDisplID ) )
  55.             if ( GetDisplayInfoData( NULL, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, NewDisplID ) )
  56.                 if ( NewNode = AllocVec( sizeof(struct ModeNode), MEMF_CLEAR ) )
  57.                 {
  58.                 NewNode->mn_Node.ln_Name = NewNode->mn_Name;
  59.                 NewNode->mn_DisplayID = NewDisplID;
  60.                 NewNode->mn_Index = Index++;
  61.                 strcpy( NewNode->mn_Name, NameInfo.Name );
  62.                 AddTail( ModeList, (struct Node *)NewNode );
  63.                 }
  64.  
  65. if ( !ModeList->lh_Head->ln_Succ )
  66.     DisplayID = 0L;
  67.  
  68. if ( DisplayID == INVALID_ID )
  69.     {
  70.     if ( NewNode = (struct ModeNode *)FindName( ModeList, DefaultModeName ) )
  71.         DisplayID = NewNode->mn_DisplayID;
  72.     else
  73.         DisplayID = PAL_MONITOR_ID;
  74.     }
  75.  
  76. return( ModeList );
  77. }
  78.  
  79.  
  80. void GetDisplayNodeFromID( void )
  81. {
  82. if ( DisplayID != 0L )
  83.     {
  84.     DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  85.  
  86.     while( DisplayNode && DisplayNode->mn_DisplayID != DisplayID )
  87.         DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  88.  
  89.     if ( !DisplayID || !DisplayNode )
  90.         {
  91.         DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  92.         DisplayID = DisplayNode->mn_DisplayID;
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98. void GetDisplayNodeFromName( void )
  99. {
  100. if ( ModeList->lh_Head->ln_Succ )
  101.     {
  102.     if ( (*DefaultModeName != 0) && (DisplayNode = (struct ModeNode *)FindName( ModeList, DefaultModeName )) )
  103.         DisplayID = DisplayNode->mn_DisplayID;
  104.     else
  105.         DisplayID = PAL_MONITOR_ID;
  106.     }
  107.     else
  108.         DisplayID = 0L;
  109. }
  110.  
  111.  
  112. void GetDisplayIDFromNode( UWORD Index )
  113. {
  114. DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  115.  
  116. while( DisplayNode && DisplayNode->mn_Index != Index )
  117.     DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  118.  
  119. DisplayID = DisplayNode->mn_DisplayID;
  120. }
  121.  
  122.  
  123. struct DisplayIDInformation *AllocDisplayIDInformation( ULONG whichDisplayID )
  124. {
  125. struct DisplayIDInformation *diinfo;
  126.  
  127. if ( diinfo = AllocVec( sizeof(struct DisplayIDInformation), MEMF_PUBLIC|MEMF_CLEAR ) )
  128.     {
  129.     if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, whichDisplayID ) )
  130.         if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, whichDisplayID ) )
  131.                 if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_MonitorInfo, sizeof(struct MonitorInfo), DTAG_MNTR, whichDisplayID ) )
  132.                     {
  133.                     diinfo->di_Brightness = briLevel;
  134.                     diinfo->di_Volume = sndLevel;
  135.                     diinfo->di_Args = FindClientNode( ActiveClient )->cn_ClientArgs;
  136.                     return( diinfo );
  137.                     }
  138.     FreeVec( diinfo );
  139.     }
  140. return( NULL );
  141. }
  142.